
Lpe.calcForce = function(i){
	var ip = i.physics;
	ip.fX=0;
	ip.fY=0;
	for(var j=0; j<ip.fm.forces.length; j++){
		var fC = ip.fm.forces[j];
		
		v= Lge.tools.vectorRotate(fC.f.vector,ip.a);
		ip.fX += v.x;
		ip.fY += v.y;
		
		if(fC.x != 0 && fC.y != 0){
			
			ip.vT += fC.x * fC.f.vector.y - fC.y * fC.f.vector.x;
			
		}
		if(fC.f.count != 0 && --fC.f.count == 0)
			ip.fm.forces.splice(j,(j--)+1);
	}
	if(ip.envForce){
		for(var j=0; j<Lpe.fm.forces.length; j++){ 
			ip.fX += Lpe.fm.forces[j].f.vector.x;
			ip.fY += Lpe.fm.forces[j].f.vector.y;
		}
	}
	
	ip.vX += ip.fX;
	ip.vY += ip.fY;	
};

Lpe.effectSpeed = function(i){
	var p = i.physics;
	p.x += p.vX * Lge.QualityRate;
	p.y += p.vY * Lge.QualityRate;
	p.a += p.vT * Lge.QualityRate * Lpe.turnFactor;
	if( p.a < 0 )
		p.a+=Math.PI*2;
};

Lpe.ForceManager = function(){
	this.forces = [];
	
	this.addForce = function(f){
		this.addCoorForce(0,0,f);
	};
	
	this.addCoorForce = function(x,y,f){
		this.forces.push({f:f,x:x,y:y});
	};
	
	this.removeForce = function(id){
		for(var i=0;i<this.forces.length;i++){
			if(this.forces[i].id == id)
				this.forces.splice(i,(i--)+1);
		}
	};
};
Lpe.fm = new Lpe.ForceManager();